import { userInfoGet } from '@/api/user'

export default {
  namespaced: true,
  state: {
    userInfo: {

    }
  },
  mutations: {
    setUserInfo (state, userInfo) {
      state.userInfo = userInfo
    }
  },
  actions: {
    async getUserInfo (context) {
      const { data: { code, data, message } } = await userInfoGet()
      console.log(data)
      if (code !== 0) return console.log('fail')
      console.log(message)
      context.commit('setUserInfo', data)
    }
  },
  getters: {
    uname (state) {
      return state.userInfo.username || state.userInfo.nickname
    },
    textAvatar (state) {
      if (state.userInfo.username) {
        return state.userInfo.username.charAt(0).toUpperCase()
      } else {
        return '测'
      }
    }
  }
}
